package com.xuecheng.teaching.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xuecheng.teaching.model.entity.Work;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface WorkMapper extends BaseMapper<Work> {

    /**
     * 查询作业绑定的课程名称列表
     * @param workId 作业ID
     * @return 课程名称列表
     */
    @Select("SELECT DISTINCT c.name FROM teachplan_work tw " +
            "LEFT JOIN course_publish c ON tw.course_pub_id = c.id " +
            "WHERE tw.work_id = #{workId}")
    String[] selectBindCourses(@Param("workId") Long workId);

    /**
     * 查询作业的答题人数
     * @param workId 作业ID
     * @return 答题人数
     */
    @Select("SELECT COUNT(DISTINCT username) FROM work_record WHERE work_id = #{workId}")
    Integer selectUserNum(@Param("workId") Long workId);
}